<?php

namespace App\Admin\Controllers;

use App\Models\Key;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Card;

class KeyController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Key::with(['user', 'site']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('site_id');
            $grid->column('api_key')->ucfirst()->substr(1, 10)->expand(function () {
                $card = new Card(null, $this->api_key);
                return "<div style='padding:10px 10px 0'>$card</div>";
            });

            $grid->column('api_secret')->ucfirst()->substr(1, 10)->expand(function () {
                $card = new Card(null, $this->api_secret);
                return "<div style='padding:10px 10px 0'>$card</div>";
            });;
            $grid->column('usdt_number', '交易所USDT数量');
            $grid->column('status');
            $grid->column('pass_phrase');
            $grid->column('listen_key')->ucfirst()->substr(1, 10)->expand(function () {
                $card = new Card(null, $this->listen_key);
                return "<div style='padding:10px 10px 0'>$card</div>";
            });;;
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user_id');
                $filter->equal('user.email', '用户邮箱');
                $filter->equal('user.mobile', '用户手机号');
                $filter->equal('site.site_name', '交易所');
            });
            $grid->disableBatchDelete();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
}
